import http from '@/utils/request'
import qs from 'qs'

const apiBefore = '/web/um'
const scheduleApiBefore = '/web/bots'

export const schedule = {
  getScheduleInfoApi: id => {
    return http.get(`${scheduleApiBefore}/sys/schedule/${id}`)
  },
  getScheduleLogApi: id => {
    return http.get(`${scheduleApiBefore}/sys/scheduleLog/${id}`)
  },
  putSchedulePauseApi: params => {
    return http.put(`${scheduleApiBefore}/sys/schedule/pause`, params)
  },
  putScheduleResumeApi: params => {
    return http.put(`${scheduleApiBefore}/sys/schedule/resume`, params)
  },
  putScheduleRunApi: params => {
    return http.put(`${scheduleApiBefore}/sys/schedule/run`, params)
  },
  postSysSchedule: params => {
    return http.post(`${scheduleApiBefore}/sys/schedule`, params)
  },
  putSysSchedule: params => {
    return http.put(`${scheduleApiBefore}/sys/schedule`, params)
  },
  // Template Fields
  getTemplateFieldsListApi: () => {
    return http.get(`${scheduleApiBefore}/sys-bot-params/list`)
  },
  getTemplateFieldsInfoApi: id => {
    return http.get(`${scheduleApiBefore}/sys-bot-params/${id}/info`)
  },
  postTemplateFieldsApi: params => {
    return http.post(`${scheduleApiBefore}/sys-bot-params`, params)
  },
  putTemplateFieldsApi: params => {
    return http.put(`${scheduleApiBefore}/sys-bot-params/${params.id}/update`, params)
  },
  deleteTemplateFieldsApi: id => {
    return http.delete(`${scheduleApiBefore}/sys-bot-params/${id}/delete`)
  },
  getScheduleListApi: params => {
    return http.get(`${apiBefore}/sys/tenant/user-work-schedule/page-user`, { params })
  },
  getUserListApi: params => {
    return http.get(`${apiBefore}/sys/user/page-obj`, { params })
  },
  getWorkScheduledUserListApi: params => {
    return http.get(`${apiBefore}/sys/user/list/select`, { params,
      paramsSerializer: params => {
        return qs.stringify(params, { indices: false })
      } })
  },
  saveBatchApi: params => {
    return http.post(`${apiBefore}/sys/tenant/user-work-schedule/save-batch`, params)
  },
  saveBatchUsersApi: params => {
    return http.post(`${apiBefore}/sys/tenant/user-work-schedule/save-batch-users`, params)
  },
  getTemplateListApi: params => {
    return http.get(`${apiBefore}/tenant/template/list`, { params })
  },
  getTemplateInfoApi: id => {
    return http.get(`${apiBefore}/tenant/template/${id}/info`)
  },
  saveTemplateInfoApi: params => {
    return http.post(`${apiBefore}/tenant/template/save`, params)
  },
  updateTemplateInfoApi: params => {
    return http.put(`${apiBefore}/tenant/template/update`, params)
  },
  deleteTemplateListApi: id => {
    return http.delete(`${apiBefore}/tenant/template/delete?id=${id}`)
  },
  switchAttendanceApi: params => {
    return http.put(`${apiBefore}/sys/user/update/attendanceFlag`, params)
  }
}
